FROM ubuntu:20.04 AS build
# :表示设置基础镜像

ARG DEBIAN_FRONTEND=noninteractive
#MAINTAINER填写编写该dockerfile的作者
ENV TZ=Asia/Shanghai

EXPOSE 18080/tcp
EXPOSE 15060/tcp
EXPOSE 15060/udp
EXPOSE 6379/tcp
EXPOSE 18081/tcp

ENV LC_ALL zh_CN.UTF-8


# 使用清华大学的apt源
RUN sed -i 's/http:\/\/archive.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu/g' /etc/apt/sources.list

# 使用了自己的settings.xml作为maven的源,加快打包速度
RUN apt-get update && \
        DEBIAN_FRONTEND="noninteractive" && \
         apt-get install -y --no-install-recommends openjdk-11-jre git maven build-essential tcl language-pack-zh-hans \
         cmake curl  vim ca-certificates  tzdata libmysqlclient-dev  redis-server libssl-dev libx264-dev libfaac-dev ffmpeg

WORKDIR /home
# 下载工具源码
RUN      git clone https://gitee.com/pan648540858/maven.git && \
         cp maven/settings.xml /usr/share/maven/conf/ && \
         git clone https://gitee.com/lvhjean/wvp-GB28181-pro.git

# wvp打包
WORKDIR /home/wvp-GB28181-pro
RUN      mvn compile && \
         mvn package && \
         mkdir -p /opt/wvp/config && \
         cp /home/wvp-GB28181-pro/target/wvp*.jar /opt/wvp/

COPY ./config/application-187.yml /opt/wvp/config/application.yml

# 清理
RUN     rm -rf /home/wiki && \
        rm -rf /home/wvp-GB28181-pro && \
        apt-get autoremove -y git maven && \
        apt-get clean -y && \
        rm -rf /var/lib/apt/lists/*dic

WORKDIR /opt/wvp
RUN     echo '#!/bin/bash' > run.sh && \
        echo 'redis-server --daemonize yes --bind 0.0.0.0' >> run.sh && \
        # echo 'cd /opt/assist' >> run.sh && \
        # echo 'nohup java -jar *.jar --userSettings.record=/opt/media/www/record/ &' >> run.sh && \
        #echo 'nohup /opt/media/MediaServer -d -m 3 &' >> run.sh && \
        echo 'cd /opt/wvp' >> run.sh && \
        echo 'nohup java -jar *.jar --spring.config.location=/opt/wvp/config/application.yml ' >> run.sh
RUN chmod +x run.sh

FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai

EXPOSE 18080/tcp
EXPOSE 15060/tcp
EXPOSE 15060/udp
EXPOSE 6379/tcp
EXPOSE 18081/tcp

ENV LC_ALL zh_CN.UTF-8

# 使用清华大学的apt源
RUN sed -i 's/http:\/\/archive.ubuntu.com/http:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu/g' /etc/apt/sources.list

WORKDIR /home
RUN apt-get update && \
        DEBIAN_FRONTEND="noninteractive" && \
        apt-get install -y --no-install-recommends openjdk-11-jre tcl language-pack-zh-hans \
        ca-certificates  tzdata libmysqlclient21  redis-server libssl1.1 libx264-155 libfaac0 ffmpeg && \
        apt-get autoremove -y && \
        apt-get clean -y && \
        rm -rf /var/lib/apt/lists/*dic

WORKDIR /opt/wvp
COPY --from=build /opt /opt
CMD ["sh", "run.sh"]
